package qscript2;

import org.qscript.Argument;
import org.qscript.Script;
import org.qscript.Token;
import org.qscript.errors.EvaluationException;
import org.qscript.operator.Operator;

public class TurnFunction extends Operator {

	public TurnFunction(String symbol, int nbrArgs, int priority, int type) {
		super(symbol, nbrArgs, priority, type);
	}

	@Override
	public Argument resolve(Script script, Token token, Argument[] args, Object... objects) throws EvaluationException {
		testForUninitialisedVars(script, args);
	    Argument a0 = args[0]; // Helicopter wrapped up in a thing object
	    Argument a1 = args[1]; // angle to turn by
		if(a0.isThing() && a1.isNumeric){
			Float ang = a1.toFloat_();
			script.fireEvent(TurnEvent.class, null, a0, new Object[] { a0.getValue(), ang });
			script.waitFor(0);
			return null;
		}

		// If we get here then the arguments are invalid
		handleInvalidArguments(script, token);
		return null;
	}

}
